package cn.xc.basic.service.impl;

import cn.xc.basic.mapper.BaseMapper;
import cn.xc.basic.query.BaseQuery;
import cn.xc.basic.service.IBaseService;
import cn.xc.basic.util.PageList;
import cn.xc.org.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public void save(T T) {
        baseMapper.save(T);
    }

    @Override
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Override
    public void update(T T) {
        baseMapper.update(T);
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        Integer count = baseMapper.queryCount(baseQuery);
        if (count==0){
            return new PageList<>();
        }
        List<T> Ts = baseMapper.queryData(baseQuery);
        return new PageList<>(count,Ts);
    }

    @Override
    public void patchRemove(List<Long> ids) {
        baseMapper.patchRemove(ids);
    }

}
